package com.workcell.workdata.xthings.constant;

import cn.hutool.core.util.StrUtil;
import lombok.experimental.UtilityClass;

/**
 * 串口主题工具类
 */
@UtilityClass
public class SerialTopicUtil {
    String PUBLISH_TOPIC_4G = "Xthings/PowerMeter/{}/wd/post";
    String SUBSCRIBE_TOPIC_4G = "Xthings/PowerMeter/{}/wd/post_reply";
    String PUBLISH_TOPIC_ETHERNET = "Xthings/SerialDevice4G/{}/wd/post";
    String SUBSCRIBE_TOPIC_ETHERNET = "Xthings/SerialDevice4G/{}/wd/post_reply";

    public String generateTopic(String deviceNo, String pattern) {
        return StrUtil.isEmpty(deviceNo) ? "" : StrUtil.format(pattern, deviceNo);
    }

    public String generatePublishTopic4G(String deviceNo) {
        return generateTopic(deviceNo, PUBLISH_TOPIC_4G);
    }

    public String generateSubscribeTopic4G(String deviceNo) {
        return generateTopic(deviceNo, SUBSCRIBE_TOPIC_4G);
    }

    public String generatePublishTopicEthernet(String deviceNo) {
        return generateTopic(deviceNo, PUBLISH_TOPIC_ETHERNET);
    }

    public String generateSubscribeTopicEthernet(String deviceNo) {
        return generateTopic(deviceNo, SUBSCRIBE_TOPIC_ETHERNET);
    }
}
